package cn.szzsi.common.model;

import cn.szzsi.common.model.base.BaseUserSing;

import java.util.Date;
import java.util.List;

/**
 * 会员签到
 * Created by haotian on 2016/12/12.
 */
//@TableBind(tableName = "b_user_sing",pkName = "id")
public class UserSing extends BaseUserSing<UserSing> {
    public static final UserSing dao=new UserSing().dao();

    //是否首次签到
    public boolean isFirstSign(String memberId){
        List<UserSing> userSign= UserSing.dao.find("select * from mall_user_sing where memberId=?",memberId);
        if(userSign.size()<1){
            return true;
        }else{
            return false;
        }
    }

    //保存签到记录
    public void saveSignRecord(int point, int continueSingDays, String remark, String memberId, String uid){
        UserSing userSign=new UserSing();
        userSign.set("point",point);
        userSign.set("continueSingDays",continueSingDays);
        userSign.set("remark",remark);
        userSign.set("memberId",memberId);
        userSign.set("uid",uid);
        userSign.set("createDate",new Date());
        userSign.save();

    }

    //获取最后一次签到记录
    public UserSing getLastSignRecord(String memberId){
        return UserSing.dao.findFirst("select * from mall_user_sing where memberId=? order by id desc limit 1",memberId);
    }


}
